<template>
  <div class="list-table">
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('基金名称')" prop="dealName">
        <el-input
          v-model="queryParams.dealName"
          :placeholder="$t('基金名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('负责人')" prop="personChargeName">
        <el-input
          v-model="queryParams.personChargeName"
          :placeholder="$t('负责人')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <!--      <el-form-item :label="$t('主体名称')" prop="personChargeName">-->
      <!--        <el-input v-model="queryParams.investName" :placeholder="$t('主体名称')" @keyup.enter.native="queryHandle" />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item v-if="queryParams.dealType === 'bf'" :label="$t('管理公司')" prop="companyName">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.companyName"-->
      <!--          :placeholder="$t('管理公司')"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="queryHandle"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="dataList" border>
      <el-table-column :label="$t('序号')" align="center" show-overflow-tooltip min-width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金名称')" align="center" prop="fundName" show-overflow-tooltip min-width="180">
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{ path:'/fund/fundBasehome', query: { id: scope.row.id }}"
            class="link_a"
          >{{ scope.row.fundName }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金管理人')" align="center" prop="fundGp" show-overflow-tooltip min-width="180">
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{path:'/fund/gpBase/gpBaseHome', query: { id: scope.row.fundGpId,gpId: scope.row.fundGpId }}"
            class="link_a"
          >{{ scope.row.fundGp }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金成立日')" align="center" prop="foundationDate" show-overflow-tooltip min-width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.foundationDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('币种')" align="center" prop="currency" :formatter="currencyFormat" :show-overflow-tooltip="true" width="90" />
      <el-table-column :label="$t('总认缴金额') + $t('金额单位')" align="center" prop="subscribedAmount" show-overflow-tooltip min-width="150">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.subscribedAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('总实缴金额') + $t('金额单位')" align="center" prop="actuallyPaidAmount" show-overflow-tooltip min-width="150">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.actuallyPaidAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('基金估值')" align="center" prop="fundValuation" show-overflow-tooltip min-width="100">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.fundValuation, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('我方认缴金额') + $t('金额单位')" align="center" prop="meSubscribedAmount" show-overflow-tooltip min-width="100">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.meSubscribedAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('我方实缴金额') + $t('金额单位')" align="center" prop="meActuallyPaidAmount" show-overflow-tooltip min-width="100">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.meActuallyPaidAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('我方所占估值')" align="center" prop="meFundValuation" show-overflow-tooltip min-width="100">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.meFundValuation, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('IRR')" align="center" prop="latestIrr" show-overflow-tooltip min-width="100">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="text"
            @click="showIrrCashFlow(scope.row.id)"
          >{{ scope.row.latestIrr }}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" fixed="right" align="center" class-name="small-padding fixed-width" width="100">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="editLpRights(scope.row.id)"
          >{{ $t("出资人权益") }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 出资人权益 -->
    <el-dialog :title="$t('出资人权益')" :visible.sync="rightsOpen" width="50%" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm">
      <fundLpRightsForm ref="fundLpRightsForm" />
    </el-dialog>

    <!-- 现金流明细 -->
    <el-dialog :title="$t('现金流明细')" :visible.sync="irrCashFlowOpen" width="50%" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogView">
      <fundToDealCashflowView ref="fundToDealCashflowView" />
    </el-dialog>

  </div>
</template>

<script>

import { queryFundPortfolioFundSpv } from '@/api/deal/projectInvestmentSituation/projectInvestmentSituationSpv'
import fundLpRightsForm from '@/views/fund/lpRights/fundLpRightsForm'
import fundToDealCashflowView from '@/views/deal/fundToDealcashflow/fundToDealCashflowView'
export default {
  components: {
    fundLpRightsForm,
    fundToDealCashflowView
  },
  data() {
    return {
      total: 0,
      loading: false,
      // 出资人权益页面
      rightsOpen: false,
      // IRR对应的现金流明细页面
      irrCashFlowOpen: false,
      // 付款币种
      currencyOptions: [],
      queryParams: {
        fundId: this.$route.query.id,
        dealType: '',
        dealName: undefined,
        personChargeName: undefined,
        companyName: undefined,
        investName: undefined,
        pageNum: 1,
        pageSize: 10
      },
      dataList: []
    }
  },
  created() {
    // 付款币种
    this.getDicts('currency').then(response => {
      this.currencyOptions = response.data
    })
  },
  mounted() {
    this.getList()
  },
  methods: {
    currencyFormat(row) {
      return this.selectDictLabel(this.currencyOptions, row.currency)
    },
    getList() {
      this.loading = true
      if (this.$route.params.dealType) {
        this.queryParams.dealType = this.$route.params.dealType
      }
      this.queryParams.fundName = this.queryParams.dealName
      queryFundPortfolioFundSpv(this.queryParams).then(response => {
        debugger
        this.dataList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.companyName = ''
      this.queryParams.personChargeName = ''
      this.queryParams.dealName = ''
      this.queryParams.investName = ''
      this.queryHandle()
    },
    // 修改出资人权益
    editLpRights(dealId) {
      this.rightsOpen = true
      this.$nextTick(() => {
        this.$refs.fundLpRightsForm.init(this.$route.query.id, dealId)
      })
    },
    // 展示出资人现金流明细
    showIrrCashFlow(dealId) {
      this.irrCashFlowOpen = true
      this.$nextTick(() => {
        this.$refs.fundToDealCashflowView.init(dealId)
      })
    }
  }
}
</script>

<style scoped>

</style>
